package com.dynamic.mybatis.core.enums;

import org.apache.ibatis.type.TypeAliasRegistry;

import java.util.HashMap;
import java.util.Map;

public class TypeAlias extends TypeAliasRegistry{
    private static TypeAliasRegistry  typeAliasRegistry = new TypeAliasRegistry();
    private static Map<Class<?>, String> typeAlias = new HashMap<>();
    static {
       for(Map.Entry<String,Class<?>> entry : typeAliasRegistry.getTypeAliases().entrySet()){
           typeAlias.put(entry.getValue(),entry.getKey());
       }
       typeAlias.put(Map.class,Type.StandardType.STRUCT.type.toLowerCase());
       typeAlias.put(HashMap.class,Type.StandardType.STRUCT.type.toLowerCase());
    }
    public static  String getTypeAlias(Class<?> clazz){
        return typeAlias.get(clazz);
    }

    public static  String getTypeAlias(String type){
        return typeAlias.get(getType(type));
    }


    public static Class<?> getType(String type){
        return typeAliasRegistry.resolveAlias(type);
    }

}
